package com.atcumt.meituan;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        // BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String s = reader.readLine();
        String substring = s.substring(1, s.length() - 1);
        String[] split = substring.split("],");
        List<List<Integer>> rooms = new ArrayList<>();
        for (int i = 0; i < split.length; i++) {
            List<Integer> list = new ArrayList<>();
            String s1;
            if (i == split.length - 1) {
                s1 = split[i].substring(1, split[i].length() - 1);
            } else {
                s1 = split[i].substring(1);
            }
            String[] ss = s1.split(",");
            for (int j = 0; j < ss.length; j++) {
                if (ss[j].length() > 0) {
                    list.add(Integer.parseInt(ss[j]));
                }
            }
            rooms.add(list);
        }
        boolean res = solve(rooms);
        System.out.println(res);
        reader.close();
    }

    private static boolean solve(List<List<Integer>> rooms) {
        List<Boolean> visited = new ArrayList<Boolean>(){{
            for(int i = 0 ; i < rooms.size(); i++){
                add(false);
            }
        }};
        dfs(0, rooms, visited);
        //检查是否都访问到了
        for (boolean flag : visited) {
            if (!flag) {
                return false;
            }
        }
        return true;
    }
    private static void dfs(int key, List<List<Integer>>  rooms, List<Boolean> visited) {
        if (visited.get(key)) {
            return;
        }
        visited.set(key, true);
        for (int k : rooms.get(key)) {
            // 深度优先搜索遍历
            dfs(k, rooms, visited);
        }
    }
}
